Preheat the oven to 425 F. Butter and flour a 10-inch pie pan. Roll out half the pastry to a thickness of 1/4 inch. Place the pastry in the pie pan. Place a piece of ham in the base of the pie crust. Sprinke some of the cheese over the ham. Repeat layers until all the ham and cheese are used up. Brush the edges of the pie crust with the beaten egg. Roll out the remaining pie crust and place it over the filling. Cut away the excess dough. Press the edges of the pie crust together between your fingers and crimp. Brush the pie with beaten egg. Prick the surface of the pie in several places with a fork and make a design in the surface with a small sharp knife. Bake for 30 minutes. Reduce heat to 350F and continue baking until the pastry is cooked. Serve warm.